open Parser

let letter = ['a' - 'z' 'A' - 'Z']
let digit = ['0'-'9']
let punc = ['~' '`' '!' '@' '#' '$' '%' '^' '&' '*' '(' ')' '-' '+' '=' ','
'.' '?' '/' '<' '>' ':' '''  ';' '{' '}' '[' ']' '|' ' ']

let double = ('-')? (digit)+ '.' (digit*)?  (* NEED TO CHECK THIS REGULAR EXPRESSION *)
let int = ('-')? (digit)+
let stringlit = '"'(letter|digit|punc|)*'"' 

rule token = parse

  ['n' '\t' ' ' '\\'] { token lexbuf } (* Ignore Whitespace *)

| "/*"     { comment lexbuf }    (* Left Comment Bracket *)
  
| '+'      { PLUS }               (* Arithmetic Operators *)
| '-'      { MINUS }
| '*'      { TIMES }
| '/'      { DIVIDE }
| '='      { ASSIGN }
| '%'      { MODULE }

| ">="     { GEQ }              (* Relational Operators *)
| "<="     { LEQ }
| ">"      { GT }
| '<'      { LT }
| "=="     { EQ }
| "!="     { NEQ }
| "==="    { EQTYPE }          (* Type Check Operators *)
| "!=="    { NEQTYPE  }

| "!"      { NOT }              (* Boolean Operators *)
| "&&"     { AND }
| "||"     { OR  }

| '^'      { CONCAT }           (* String Operators *)

| "+>"     {ADDR}              (* List Operators *)
| "<+"     {ADDL}     
| "<-"     {REMOVEL}
| "->"     {REMOVER}


| ';'      { SEMI }             (* Punctuation *)
| '('      { LPAREN }           
| ')'      { RPAREN }
| '{'      { LBRACE }
| '}'      { RBRACE }
| ','      { COMMA }

| "anytype" { ANYTYPE }         (* Keywords *)
| "bool"    { BOOL }
| "card"    { CARD }						
| "def"     { DEF }
| "double"  { DOUBLE }
| "ele"     { ELE }
| "else"    { ELSE }
| "false"   { FALSE }
| "foreach" { FOREACH }
| "if"      { IF }
| "int"     { INT }
| "list"    { LIST }
| "player"  { PLAYER }
| "return"  { RETURN }
| "string"  { STRING }
| "true"    { TRUE }
| "while"   { WHILE }
| "your"    { YOUR }

| eof { EOF }
| _ as char { raise (Failure("illegal character " ^ Char.escaped char)) }

and comment = parse
  "*/" { token lexbuf }       (* Right Bracket *)
| _    { comment lexbuf }
